/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ds_Queue;

/**
 *
 * @author hcc25_000
 */
public class MyLinkedQueue<T> implements MyQueueADT<T> {
    private int count;
    private MyLinerNode<T> head,tail;
    
    public MyLinkedQueue(){
        count=0;
        head=tail=null;
    }
    
    public void enqueue(T element){
        MyLinerNode<T> node=new MyLinerNode<T>(element);
        if(isEmpty())
            head=node;
        else
            tail.setNext(node);
        tail=node;
        count++;
    }
    
    public T dequeue(){
        if(isEmpty())
            throw new MyEmptyCollectionException("queue");
        
        T result=head.getElement();
        head=head.getNext();
        count--;
        
        if(isEmpty())
            tail=null;
        return result;
    }
    
    public T first(){
        if(isEmpty())
            throw new MyEmptyCollectionException("queue");
        
        return head.getElement();
    }
    
    public int size(){
        return count;
    }
    
    public boolean isEmpty(){
        return count==0;
    }
    
    public String toString(){
        return new String("queue");
    }
    
    public void showInfo(){
        if(isEmpty())
            throw new MyEmptyCollectionException("queue");
        
        MyLinerNode<T> guide=head;
        while(guide!=null){
            T result=guide.getElement();
            System.out.println(""+result);
            guide=guide.getNext();
        }
    }
}
